import draw.*;
import geometry.*;
import tester.*;
import tester.cobertura.Instrument;

import java.util.*;
import colors.*;

@Instrument
class Tile{
  /**
 * @uml.property  name="width"
 */
int width = 10;
  /**
 * @uml.property  name="height"
 */
int height = 20;
  /**
 * @uml.property  name="pos"
 * @uml.associationEnd  multiplicity="(1 1)"
 */
Posn pos;
  /**
 * @uml.property  name="col"
 * @uml.associationEnd  multiplicity="(1 1)"
 */
IColor col;
  /**
 * @uml.property  name="s"
 */
int s = 1;
  
  Tile(Posn pos,IColor col){
    this.pos = pos;
    this.col = col;
  }
  
  // returns a Posn that represents the center coords of the Tile.
  Posn center(){
	  return new Posn (this.pos.x + (width / 2), this.pos.y + (height/ 2));
  }
  
  // Takes a player and returns a number that is the distance of the x-coords between the two.
  double distanceToX(Player p){
	  return Math.abs(this.center().x - p.center().x);
  }
  
  //Takes a player and returns a number that is the distance of the y-coords between the two.
  double distanceToY(Player p){
	  return Math.abs(this.center().y - p.center().y);
  }
  
  //is this tile hit by the player?
  boolean hitp(Player p){
	  return this.distanceToX(p) < ((this.width + p.width) / 2) &&
	  	     this.distanceToY(p) < ((this.height + p.height) / 2);
  }
  
  //has this tile hit the ground?
  boolean hitGroundp(){
	  return this.pos.x > 600;
  }
 
  // updates according to the clock.
  Tile onTick(){
    return new Tile(new Posn(this.pos.x,this.pos.y+s), this.col);
  }
  
  // Draws the tile.
  boolean draw(Canvas c){
    return c.drawRect(this.pos, this.width, this.height, this.col);
  }
  /*
  TEMPLATE:
     FIELDS:
      ... this.width ...        --int
      ... this.height ...       --Posn
      ... this.pos...           --int
      ... this.col ...          --IColor
      ... this.s ...            --int

      METHODS:
      ... this.onTick() ...             -- Tile
      ... this.hitGroundp() ...         -- boolean
      ... this.draw(Canvas c) ...       -- boolean
      ... this.hitp(Player p) ...       -- boolean
      ... this.distanceToX(Player p) ...-- double
      ... this.distanceToY(Player p) ...-- double
      ... this.center() ...             -- Posn

      METHODS FOR FIELDS:
      n/a
  */ 
}